package com.sanjiahantang.youjiaclient.module.common.holders;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;


import com.sanjiahantang.youjiaclient.R;
import com.sanjiahantang.youjiaclient.config.ConfigValue;
import com.sanjiahantang.youjiaclient.module.cases.views.impl.CaseActivity;
import com.sanjiahantang.youjiaclient.module.login.views.impl.LoginActivity;
import com.sanjiahantang.youjiaclient.module.common.views.impl.MainActivity;
import com.sanjiahantang.youjiaclient.module.decorate.views.impl.DecorateFormActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/8.
 */

public class ClassifyHolder extends RecyclerView.ViewHolder{
    private Context context;

    MainActivity activity;
    GridView rv_menu;
    List<Integer> list=new ArrayList<>();



    public ClassifyHolder(View itemView, Context context, MainActivity activity) {
        super(itemView);
        this.context = context;
        this.activity = activity;
        for (int i=0;i<4;i++)
        {
            list.add(i);
        }
        ClassAdapter adapter=new ClassAdapter(list);
        rv_menu= (GridView) itemView.findViewById(R.id.rv_home_menu);

        rv_menu.setAdapter(adapter);

    }


    public class ClassAdapter extends BaseAdapter
    {
        List<Integer> data;
        LayoutInflater inflater;

        public ClassAdapter(List<Integer> data)
        {
            inflater=LayoutInflater.from(context);
            this.data=data;

        }

        @Override
        public int getCount() {
            return data.size();
        }

        @Override
        public Object getItem(int position) {
            return data.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView = inflater.inflate(R.layout.item_subject,null);
            TextView txtTitle= (TextView) convertView.findViewById(R.id.tv_info);
            ImageView iv_pic= (ImageView) convertView.findViewById(R.id.iv_icon);
            switch (position)
            {
                case 0:
                    txtTitle.setText("我要装修");
                    iv_pic.setImageDrawable(context.getResources().getDrawable(R.drawable.i_pen));
                    convertView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                            if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)){
                                context.startActivity(new Intent(context,DecorateFormActivity.class));
                            }else{
                                LoginActivity.logout(context);
                            }

                        }
                    });
                    break;
                case 1:
                    txtTitle.setText("装修管理");
                    iv_pic.setImageDrawable(context.getResources().getDrawable(R.drawable.i_computer));
                    convertView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            ((MainActivity)context).setFragmentIndex(1);
                        }
                    });
                    break;
                case 2:
                    txtTitle.setText("家居商城");
                    iv_pic.setImageDrawable(context.getResources().getDrawable(R.drawable.i_bass));
                    convertView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            ((MainActivity)context).setFragmentIndex(2);
                        }
                    });
                    break;
                case 3:
                    txtTitle.setText("风格汇");
                    iv_pic.setImageDrawable(context.getResources().getDrawable(R.drawable.i_sofa));
                    convertView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            context.startActivity(new Intent(context,CaseActivity.class));
                        }
                    });
                    break;

            }

            return convertView;
        }
    }


   /* @Override
    public void onClick(View v) {

        switch (v.getId())
        {

            case R.id.tv_classmain_fitmentmanage:

                break;
            case R.id.tv_classmain_gofitment:
                activity.setFragmentIndex(1);
                break;
            case R.id.tv_classmain_store:

                break;
            case R.id.tv_classmain_style:

                break;
        }
    }*/
}
